import re
import os
from datetime import datetime

class TenderTextEditor:
    def __init__(self):
        self.text_materials = {}
        self.categories = set()

    def collect_text(self, file_path):
        if not os.path.isfile(file_path):
            return False
        with open(file_path, 'r', encoding='utf-8') as file:
            content = file.read()
        file_name = os.path.basename(file_path)
        self.text_materials[file_name] = content
        return True

    def classify_text(self, file_name, category):
        if file_name in self.text_materials:
            self.categories.add(category)
            return True
        return False

    def organize_text(self):
        organized_text = ''
        for category in sorted(self.categories):
            organized_text += f'### {category} ###\n'
            for file_name, content in self.text_materials.items():
                # 这里可以添加更复杂的分类逻辑
                organized_text += f'## {file_name} ##\n{content}\n\n'
        return organized_text

    def unify_format(self, text, style='standard'):
        if style == 'standard':
            text = re.sub('\s+', ' ', text)
            text = re.sub('\n+', '\n', text)
        return text

    def add_annotation(self, text, annotation, position):
        return text[:position] + f'[注释: {annotation}]' + text[position:]

    def batch_replace(self, text, replacements):
        for old_str, new_str in replacements.items():
            text = re.sub(re.escape(old_str), new_str, text)
        return text

    def reminder(self, task, due_date):
        today = datetime.today()
        due = datetime.strptime(due_date, '%Y-%m-%d')
        if today >= due:
            print(f'提醒: {task} 已到期！')
        else:
            days_left = (due - today).days
            print(f'提醒: {task} 将在 {days_left} 天后到期。')

if __name__ == '__main__':
    editor = TenderTextEditor()
    # 示例用法
    editor.collect_text('example.txt')
    editor.classify_text('example.txt', '项目背景')
    organized = editor.organize_text()
    formatted = editor.unify_format(organized)
    annotated = editor.add_annotation(formatted, '重要信息', 10)
    replaced = editor.batch_replace(annotated, {'项目名称': '新的项目名称'})
    editor.reminder('提交投标文件', '2024-12-31')